﻿namespace WMS6.Services
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.ServiceModel;
    using System.ServiceModel.Activation;
    using WMS6.BLL;
    using WMS6.Common;
    using WMS6.DataEntity;
    using WMS6.QueryEntity;

    [ServiceBehavior(InstanceContextMode=InstanceContextMode.PerCall), AspNetCompatibilityRequirements(RequirementsMode=AspNetCompatibilityRequirementsMode.Allowed)]
    public class OrderMgtService : IOrderMgtService
    {
        public string ClosePurchaseOrder(List<string> poIDs, PubParasInfo pubParasInfo)
        {
            string returnStr = string.Empty;
            try
            {
                returnStr = new PurchaseOrderBLL(pubParasInfo).ClosePurchaseOrder(poIDs);
                new OperationLogBLL(pubParasInfo).Insert("OrderMgtService_Close_PurchaseOrder", poIDs, pubParasInfo);
                return returnStr;
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "InboundService异常");
            }
            return returnStr;
        }

        public string ConvertSalesOrder2ShippingOrder(List<string> orderID, PubParasInfo pubParasInfo)
        {
            string temp = string.Empty;
            try
            {
                temp = new SalesOrderBLL(pubParasInfo).ConvertSalesOrder2ShippingOrder(orderID);
                new OperationLogBLL(pubParasInfo).Insert("OrderMgtService_Submit_SalesOrder", orderID, pubParasInfo);
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "OrderMgtService异常");
            }
            return temp;
        }

        public string DeletePurchaseOrder(List<string> poIDs, PubParasInfo pubParasInfo)
        {
            string temp = string.Empty;
            try
            {
                temp = new PurchaseOrderBLL(pubParasInfo).DeletePurchaseOrder(poIDs);
                new OperationLogBLL(pubParasInfo).Insert("OrderMgtService_Delete_PurchaseOrder", poIDs, pubParasInfo);
                return temp;
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "OrderMgtService异常");
            }
            return temp;
        }

        public string DeleteSalesOrderInfo(List<string> orderID, PubParasInfo pubParasInfo)
        {
            string temp = string.Empty;
            try
            {
                temp = new SalesOrderBLL(pubParasInfo).DeleteSalesOrderInfo(orderID);
                new OperationLogBLL(pubParasInfo).Insert("OrderMgtService_Delete_SalesOrder", orderID, pubParasInfo);
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "OrderMgtService异常");
            }
            return temp;
        }

        public DataSet GetAllInfoPurchaseOrder(PubParasInfo pubParasInfo)
        {
            try
            {
                PurchaseOrderBLL purchaseOrderBll = new PurchaseOrderBLL(pubParasInfo);
                return purchaseOrderBll.GetAllInfoPurchaseOrder();
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "OrderMgtService异常");
            }
            return null;
        }

        public PurchaseOrderInfo GetPurchaseOrderInfoByID(string poID, PubParasInfo pubParasInfo)
        {
            PurchaseOrderInfo purchaseOrder = new PurchaseOrderInfo();
            try
            {
                PurchaseOrderBLL purchaseOrderBll = new PurchaseOrderBLL(pubParasInfo);
                return purchaseOrderBll.GetPurchaseOrderInfoByID(poID);
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "OrderMgtService异常");
            }
            return purchaseOrder;
        }

        public DataSet GetPurchaseOrderInfoByQueryEntity(PurchaseOrderQueryEntity purchaseOrderQueryEntity, PubParasInfo pubParasInfo)
        {
            try
            {
                PurchaseOrderBLL purchaseOrderBll = new PurchaseOrderBLL(pubParasInfo);
                return purchaseOrderBll.GetPurchaseOrderInfoByQueryEntity(purchaseOrderQueryEntity);
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "OrderMgtService异常");
            }
            return null;
        }

        public DataSet GetSalesOrderByQueryEntity(SalesOrderQueryEntity salesOrderQueryEntity, PubParasInfo pubParasInfo)
        {
            try
            {
                SalesOrderBLL salesOrderBLL = new SalesOrderBLL(pubParasInfo);
                return salesOrderBLL.GetSalesOrderByQueryEntity(salesOrderQueryEntity);
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "OrderMgtService异常");
            }
            return null;
        }

        public SalesOrderInfo GetSalesOrderInfoByID(string salesOrderID, PubParasInfo pubParasInfo)
        {
            SalesOrderInfo salesOrderInfo = new SalesOrderInfo();
            try
            {
                salesOrderInfo = new SalesOrderBLL(pubParasInfo).GetSalesOrderInfoByID(salesOrderID);
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "OrderMgtService异常");
            }
            return salesOrderInfo;
        }

        public SalesOrderInfo ImportSoByDataSet(DataSet ds, PubParasInfo pubParasInfo)
        {
            try
            {
                SalesOrderBLL salesOrderBLL = new SalesOrderBLL(pubParasInfo);
                return salesOrderBLL.GetImportByDataSet(ds);
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorHandler(ex, LogType.Error);
            }
            return null;
        }

        public string InserOnLinePurchaseOrder(PurchaseOrderInfo purchaseOrderInfo, PubParasInfo pubParasInfo)
        {
            string lineID = string.Empty;
            try
            {
                lineID = new PurchaseOrderBLL(pubParasInfo).InserOnLinePurchaseOrder(purchaseOrderInfo);
                new OperationLogBLL(pubParasInfo).Insert("OrderMgtService_Insert_PurchaseOrder", purchaseOrderInfo, pubParasInfo);
                return lineID;
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "OrderMgtService异常");
            }
            return lineID;
        }

        public string InserPurchaseOrder(PurchaseOrderInfo purchaseOrderInfo, PubParasInfo pubParasInfo)
        {
            string lineID = string.Empty;
            try
            {
                lineID = new PurchaseOrderBLL(pubParasInfo).InserPurchaseOrder(purchaseOrderInfo);
                new OperationLogBLL(pubParasInfo).Insert("OrderMgtService_Insert_PurchaseOrder", purchaseOrderInfo, pubParasInfo);
                return lineID;
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "OrderMgtService异常");
            }
            return lineID;
        }

        public string InsertSalesOrderInfo(SalesOrderInfo salesOrderInfo, PubParasInfo pubParasInfo)
        {
            string lineID = string.Empty;
            try
            {
                lineID = new SalesOrderBLL(pubParasInfo).InsertSalesOrderInfo(salesOrderInfo);
                new OperationLogBLL(pubParasInfo).Insert("OrderMgtService_Insert_SalesOrder", salesOrderInfo, pubParasInfo);
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "OrderMgtService异常");
            }
            return lineID;
        }

        public string SalesOrderCancel(string orderID, PubParasInfo pubParasInfo)
        {
            string temp = string.Empty;
            try
            {
                temp = new SalesOrderBLL(pubParasInfo).SalesOrderCancel(orderID);
                new OperationLogBLL(pubParasInfo).Insert("OrderMgtService_Cancel_SalesOrder", orderID, pubParasInfo);
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "OrderMgtService异常");
            }
            return temp;
        }

        public string TJConvertSalesOrder2ShippingOrder(List<string> orderID, PubParasInfo pubParasInfo)
        {
            string temp = string.Empty;
            try
            {
                temp = new SalesOrderBLL(pubParasInfo).TJConvertSalesOrder2ShippingOrder(orderID);
                new OperationLogBLL(pubParasInfo).Insert("OrderMgtService_Submit_SalesOrder", orderID, pubParasInfo);
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "OrderMgtService异常");
            }
            return temp;
        }

        public string TJInsertSalesOrderInfo(SalesOrderInfo salesOrderInfo, PubParasInfo pubParasInfo)
        {
            string lineID = string.Empty;
            try
            {
                lineID = new SalesOrderBLL(pubParasInfo).TJInsertSalesOrderInfo(salesOrderInfo);
                new OperationLogBLL(pubParasInfo).Insert("OrderMgtService_Insert_SalesOrder", salesOrderInfo, pubParasInfo);
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "OrderMgtService异常");
            }
            return lineID;
        }

        public string TJUpdateOnLineSO(SalesOrderInfo salesOrderInfo, PubParasInfo pubParasInfo)
        {
            string temp = string.Empty;
            try
            {
                temp = new SalesOrderBLL(pubParasInfo).TJUpdateOnLineSO(salesOrderInfo);
                new OperationLogBLL(pubParasInfo).Insert("OrderMgtService_Update_SalesOrder_Online", salesOrderInfo, pubParasInfo);
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "OrderMgtService异常");
            }
            return temp;
        }

        public string TTConvertSalesOrder2ShippingOrder(List<string> orderID, PubParasInfo pubParasInfo)
        {
            string temp = string.Empty;
            try
            {
                temp = new SalesOrderBLL(pubParasInfo).TTConvertSalesOrder2ShippingOrder(orderID);
                new OperationLogBLL(pubParasInfo).Insert("OrderMgtService_Submit_SalesOrder", orderID, pubParasInfo);
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "OrderMgtService异常");
            }
            return temp;
        }

        public string TTInsertSalesOrderInfo(SalesOrderInfo salesOrderInfo, PubParasInfo pubParasInfo)
        {
            string lineID = string.Empty;
            try
            {
                lineID = new SalesOrderBLL(pubParasInfo).TTInsertSalesOrderInfo(salesOrderInfo);
                new OperationLogBLL(pubParasInfo).Insert("OrderMgtService_Insert_SalesOrder", salesOrderInfo, pubParasInfo);
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "OrderMgtService异常");
            }
            return lineID;
        }

        public string TTUpdateOnLineSO(SalesOrderInfo salesOrderInfo, PubParasInfo pubParasInfo)
        {
            string temp = string.Empty;
            try
            {
                temp = new SalesOrderBLL(pubParasInfo).TTUpdateOnLineSO(salesOrderInfo);
                new OperationLogBLL(pubParasInfo).Insert("OrderMgtService_Update_SalesOrder_Online", salesOrderInfo, pubParasInfo);
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "OrderMgtService异常");
            }
            return temp;
        }

        public string UpdateOnLinePurchaseOrder(PurchaseOrderInfo purchaseOrderInfo, PubParasInfo pubParasInfo)
        {
            string lineID = string.Empty;
            try
            {
                lineID = new PurchaseOrderBLL(pubParasInfo).UpdateOnLinePurchaseOrder(purchaseOrderInfo);
                new OperationLogBLL(pubParasInfo).Insert("OrderMgtService_Update_PurchaseOrder", purchaseOrderInfo, pubParasInfo);
                return lineID;
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "OrderMgtService异常");
            }
            return lineID;
        }

        public string UpdateOnLineSO(SalesOrderInfo salesOrderInfo, PubParasInfo pubParasInfo)
        {
            string temp = string.Empty;
            try
            {
                temp = new SalesOrderBLL(pubParasInfo).UpdateOnLineSO(salesOrderInfo);
                new OperationLogBLL(pubParasInfo).Insert("OrderMgtService_Update_SalesOrder_Online", salesOrderInfo, pubParasInfo);
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "OrderMgtService异常");
            }
            return temp;
        }

        public string UpdatePurchaseOrder(PurchaseOrderInfo purchaseOrderInfo, PubParasInfo pubParasInfo)
        {
            string lineID = string.Empty;
            try
            {
                lineID = new PurchaseOrderBLL(pubParasInfo).UpdatePurchaseOrder(purchaseOrderInfo);
                new OperationLogBLL(pubParasInfo).Insert("OrderMgtService_Update_PurchaseOrder", purchaseOrderInfo, pubParasInfo);
                return lineID;
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "OrderMgtService异常");
            }
            return lineID;
        }

        public string UpdateSalesOrderInfo(SalesOrderInfo salesOrderInfo, PubParasInfo pubParasInfo)
        {
            string lineID = string.Empty;
            try
            {
                lineID = new SalesOrderBLL(pubParasInfo).UpdateSalesOrderInfo(salesOrderInfo);
                new OperationLogBLL(pubParasInfo).Insert("OrderMgtService_Update_SalesOrder", salesOrderInfo, pubParasInfo);
            }
            catch (Exception ex)
            {
                CommonErrorHandler.ErrorTypeExchange(ex, "OrderMgtService异常");
            }
            return lineID;
        }
    }
}

